**************************************************************
*HURRICANES AND GAS GOUGING - SUMMARY STATISTICS
**************************************************************
frame copy default sum_stats, replace
frame change sum_stats
keep if sample_main==1
gsort station_id date

**************************************************************
*TABLE 1 - SUMMARY STATISTICS (2004-2008)

***************
*SUMMARY STATISTICS - ALL PERIODS
*Retail Prices - All
qui sum retail, det
	scalar ret_mean = r(mean)	
	scalar ret_se=r(sd)
	scalar ret_ntot=r(N) 
qui gdistinct station_id 
	scalar ret_nstat=r(ndistinct) 
	
*Retail Prices - Branded Major
qui sum retail if brand_maj==1, det
	scalar ret_br_mean = r(mean)	
	scalar ret_br_se=r(sd)
	scalar ret_br_ntot=r(N) 
qui gdistinct station_id if brand_maj==1
	scalar ret_br_nstat=r(ndistinct) 
	
*Retail Prices - Retail Major
qui sum retail if ret_maj==1, det
	scalar ret_rm_mean = r(mean)	
	scalar ret_rm_se=r(sd)
	scalar ret_rm_ntot=r(N) 
qui gdistinct station_id if ret_maj==1
	scalar ret_rm_nstat=r(ndistinct) 
	
*Retail Prices - Coastal 
qui sum retail if coast_pfz==1, det
	scalar ret_co_mean = r(mean)	
	scalar ret_co_se=r(sd)
	scalar ret_co_ntot=r(N) 
qui gdistinct station_id if coast_pfz==1
	scalar ret_co_nstat=r(ndistinct) 

*Retail Prices - Inland 
qui sum retail if coast_pfz==0, det
	scalar ret_in_mean = r(mean)	
	scalar ret_in_se=r(sd)
	scalar ret_in_ntot=r(N) 
qui gdistinct station_id if coast_pfz==0
	scalar ret_in_nstat=r(ndistinct) 
	
*Wholesale Prices - All
qui sum wholesale, det
	scalar whole_mean = r(mean)	
	scalar whole_se=r(sd)
	scalar whole_ntot=r(N) 
qui gdistinct nearRack1 
	scalar whole_nstat=r(ndistinct) 	
 
*Bulk Prices - All
qui sum bulk, det
	scalar bulk_mean = r(mean)	
	scalar bulk_se=r(sd)
	scalar bulk_ntot=r(N) 

***************
*SUMMARY STATISTICS - STATION CHARACTERISTICS

*Highway Distance
qui sum hw_dist, det
	scalar hw_mean = r(mean)	
	scalar hw_se=r(sd)
	scalar hw_ntot=r(N) 
qui gdistinct station_id 
	scalar hw_nstat=r(ndistinct) 
	
*Distance to Nearest Competitor
qui sum km_to_nearestID_df, det
	scalar dist_mean = r(mean)	
	scalar dist_se=r(sd)
	scalar dist_ntot=r(N) 
qui gdistinct station_id 
	scalar dist_nstat=r(ndistinct) 
	
*No. Competitors within 5 km
qui sum within_5km_df, det
	scalar comp_mean = r(mean)	
	scalar comp_se=r(sd)
	scalar comp_ntot=r(N) 	
qui gdistinct station_id 
	scalar comp_nstat=r(ndistinct) 
	
***	
*Creating matrix
matrix A = (scalar(ret_mean),     scalar(ret_se),    scalar(ret_ntot),    scalar(ret_nstat)  \ ///
			scalar(ret_br_mean),     scalar(ret_br_se),    scalar(ret_br_ntot),    scalar(ret_br_nstat)  \ ///
			scalar(ret_rm_mean),     scalar(ret_rm_se),    scalar(ret_rm_ntot),    scalar(ret_rm_nstat)  \ ///
			scalar(ret_co_mean),     scalar(ret_co_se),    scalar(ret_co_ntot),    scalar(ret_co_nstat)  \ ///
			scalar(ret_in_mean),     scalar(ret_in_se),    scalar(ret_in_ntot),    scalar(ret_in_nstat)  \ ///
			scalar(whole_mean),     scalar(whole_se),    scalar(whole_ntot),    scalar(whole_nstat)  \ ///
			scalar(bulk_mean),     scalar(bulk_se),    scalar(bulk_ntot),     999 \ ///
			scalar(hw_mean),     scalar(hw_se),    scalar(hw_ntot),     scalar(hw_nstat)  \ ///
			scalar(dist_mean),     scalar(dist_se),    scalar(dist_ntot),    scalar(dist_nstat)  \ ///
			scalar(comp_mean),     scalar(comp_se),    scalar(comp_ntot),    scalar(comp_nstat) )
	   
mat rownames A = "Retail Price ($/gal)" "Branded Major ($/gal)" ///
				"Major Retailer ($/gal)" "Coastal ($/gal)" ///
				"Inland ($/gal)" "Wholesale Price ($/gal)" ///
				"Bulk Price ($/gal)" ///
				"Distance to Highway (km)" "Distance to Competitor (km)" ///
				"Competitors within 5km"	
				
mat colnames A = "Mean" "Std Deviation" "N" "N (Stations)"

esttab matrix(A, fmt(2)) using "$output\sumstats_main_$outputdate.csv", replace  ///
     title(Summary Statistics: Prices and Station Characteristics) 
frame change default